from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from wecom_practice.base.base_page import BasePage
from wecom_practice.page.add_member_page import AddMemberPage


class ContactPage(BasePage):
    # 成员列表
    __MEMBER_LIST = By.ID, "member_list"
    # 添加成员按钮
    __ADD_MEMBER_BTN = By.CSS_SELECTOR, ".member_operationBar .js_add_member"
    # 提示信息
    __TIP_INFO = By.ID, "js_tips"
    # 列表中的成员姓名
    __MEMBER_NAME = By.CSS_SELECTOR, ".member_colRight_memberTable_td:nth-child(2)"

    def goto_add_member_page(self):
        '''
        点击添加成员按钮，跳转至添加成员页面
        :return:
        '''
        # WebDriverWait(self.driver, 10).until(
        #     expected_conditions.visibility_of_element_located(
        #         (By.ID, "member_list")
        #     )
        # )
        # self.driver.find_element(By.CSS_SELECTOR, ".member_colRight_cnt_operation .js_add_member").click()
        self.wait_ele_located(*self.__MEMBER_LIST)
        self.click_ele(*self.__ADD_MEMBER_BTN)
        return AddMemberPage(self.driver)

    def get_tips(self):
        '''
        获取操作结果的提示信息
        :return:
        '''
        # tips = WebDriverWait(self.driver, 10).until(
        #     expected_conditions.element_to_be_clickable(
        #         (By.ID, "js_tips")
        #     )
        # ).text
        tips=self.find_and_get_text(*self.__TIP_INFO)
        return tips

    def get_contact_member_list(self):
        '''
        获取通讯录页面用户等率列表
        :return:
        '''
        # WebDriverWait(self.driver, 10).until(
        #     expected_conditions.element_to_be_clickable(
        #         (By.ID, "member_list")
        #     )
        # )
        self.wait_ele_click(*self.__MEMBER_LIST)
        # 获取成员列表信息
        # names = self.driver.find_elements(
        #     By.CSS_SELECTOR, ".member_colRight_memberTable_td:nth-child(2)"
        # )
        names=self.find_eles(*self.__MEMBER_LIST)
        name_list = [n.text for n in names]


        return name_list